﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Practices.Unity;
using System.Configuration;
using Microsoft.Practices.Unity.Configuration;

namespace Infrastructure.Aspect.Test
{
    public class UnityHelper
    {
        public static IUnityContainer BuildUnityContainer() 
        {
            var Container = Infrastructure.Aspect.Patterns.Singleton<UnityContainer,IUnityContainer>.Instance;
            
            

            var fileMapPolicies = new ExeConfigurationFileMap { ExeConfigFilename =  System.IO.Path.Combine(System.AppDomain.CurrentDomain.BaseDirectory,  @".\Config\Aspect.config")};
            var configurationPolicies = ConfigurationManager.OpenMappedExeConfiguration(fileMapPolicies, ConfigurationUserLevel.None);
            var unitySectionPolicies = (UnityConfigurationSection)configurationPolicies.GetSection("unity");            
            Container.LoadConfiguration(unitySectionPolicies);            


            return Container; 

        }
    }
}
